Module Misc
    Public DebugTxt As String

    Public RTS As TVRenderSurface

    Public Sub Load()
        '<Load everything here>'


        World_Load() 'Load textures.

        RTS = Scene.CreateRenderSurface(256, 256)

        TV.SetVSync(True)
        OpenMap()
    End Sub

    Public Sub Update()
        '<Update everything here>'
        World_Tick()
    End Sub

    'MouseGridPos
    Dim mGx2, mGy2 As Short
    Public Sub RenderGame()
        RTS.StartRender()

        Scr2D.Action_Begin2D()
        'Draw the tiles.
        Scr2D.Draw_Texture(World.mapRS.GetTexture, 0, 0, MapSizePx - 1, MapSizePx - 1)

        Render_NPC()

        mGx2 = MouseGrid.X * 16
        mGy2 = MouseGrid.Y * 16
        'Draw a box on the current tile.
        Scr2D.Draw_Box(mGx2, mGy2, mGx2 + 15, mGy2 + 15)

        'Is it summer?
        If World.Time.Month > 5 And World.Time.Month < 8 Then
            'Draw time of day.
            Select Case World.Time.Hour
                Case 18 'Turning night
                    Scr2D.Draw_FilledBox(0, 0, MapSizePx - 1, MapSizePx - 1, RGBA(0, 0, 0, World.Time.Minute / 75))
                Case 19 To 24, 0 To 4 'Night
                    Scr2D.Draw_FilledBox(0, 0, MapSizePx - 1, MapSizePx - 1, RGBA(0, 0, 0, 0.8))
                Case 5 'Turning day
                    Scr2D.Draw_FilledBox(0, 0, MapSizePx - 1, MapSizePx - 1, RGBA(0, 0, 0, 0.8 - (World.Time.Minute / 75)))
            End Select
        Else
            'Draw time of day.
            Select Case World.Time.Hour
                Case 19 'Turning night
                    Scr2D.Draw_FilledBox(0, 0, MapSizePx - 1, MapSizePx - 1, RGBA(0, 0, 0, World.Time.Minute / 75))
                Case 20 To 24, 0 To 5 'Night
                    Scr2D.Draw_FilledBox(0, 0, MapSizePx - 1, MapSizePx - 1, RGBA(0, 0, 0, 0.8))
                Case 6 'Turning day
                    Scr2D.Draw_FilledBox(0, 0, MapSizePx - 1, MapSizePx - 1, RGBA(0, 0, 0, 0.8 - (World.Time.Minute / 75)))
            End Select
        End If


        Scr2D.Action_End2D()



        RTS.EndRender()
    End Sub

    'Render the 2d stuff.
    Public Sub Render2D()
        Scr2D.Action_Begin2D()
        'Draw the game.
        Scr2D.Draw_Texture(RTS.GetTexture, 0, 100, 255, 355)


        'Draw the tile.
        Scr2D.Draw_Texture(TileTex(CurrentTile), 180, 10, 195, 25)


        Scr2D.Action_End2D()



        ScrText.Action_BeginText()

        'Draw the time.
        ScrText.NormalFont_DrawText(World.Time.ToString, 650, 2, GrgbA(0.6, 1))
        'Draw the mouse position in the grid.
        ScrText.NormalFont_DrawText(MouseGrid.X & ", " & MouseGrid.Y, 400, 2, GrgbA(0.6, 1))

        'Draw the current tile info.
        ScrText.NormalFont_DrawText("Tile# " & CurrentTile, 200, 10, GrgbA(0.6, 1))
        'Get the path finding unmber.
        Dim num As Integer = Right(Tex.GetTextureInfo(TileTex(CurrentTile)).Name, Tex.GetTextureInfo(TileTex(CurrentTile)).Name.Length - InStr(Tex.GetTextureInfo(TileTex(CurrentTile)).Name, "_"))
        ScrText.NormalFont_DrawText("Tile: " & num, 200, 21, GrgbA(0.6, 1))

        ScrText.NormalFont_DrawText("Home #" & CurrentHome, 100, 10, GrgbA(0.5, 1))

        ScrText.NormalFont_DrawText(DebugTxt, 650, 100, GrgbA(0.6, 1))
        ScrText.Action_EndText()

    End Sub


    Public Function PointToString(ByVal Point As Point) As String
        Return Point.X & "," & Point.Y
    End Function

End Module
